package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bed")
@Api("床位管理")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    @GetMapping("/read/room/{roomId}")
    @ApiOperation("根基房间Id查询床位")
    public ResponseResult<List<BedVo>> readBedByRoomId(
            @ApiParam(value = "房间ID", required = true) @PathVariable("roomId") Long roomId) {
        List<BedVo> beds = bedService.getBedsByRoomId(roomId);
        return success(beds);
    }

    /**
     * 新增床位
     * @param bedDto
     * @return
     */
    @PostMapping("/create")
    @ApiOperation(value = "新增床位")
    public ResponseResult createBed(@RequestBody BedDto bedDto){
        bedService.addBed(bedDto);
        return success();
    }

    /**
     * 根据id查询床位
     * @param id
     * @return
     */
    @GetMapping("/read/{id}")
    @ApiOperation("根据id查询床位")
    public ResponseResult queryById(@ApiParam(value = "床位ID",readOnly = true) @PathVariable Long id){
        BedVo bed = bedService.getByIdBad(id);
        return ResponseResult.success(bed);
    }

    /**
     * 删除床位
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("根据id删除床位")
    public ResponseResult deleteBedById(@PathVariable("id") Long id){
        bedService.deleteBedById(id);
        return success();
    }

    /**
     * 更新床位
     * @param bed
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改床位")
    public ResponseResult updateBed(@RequestBody BedDto bed){
        bedService.updateBed(bed);
        return success();
    }

}
